import numpy as np
import matplotlib.pyplot as plt

# read the data from problemB_n.txt
data1 = np.loadtxt('./data/problemB_2.txt')
point1 = data1[:, 0]
value1 = data1[:, 1]

data2 = np.loadtxt('./data/problemB_4.txt')
point2 = data2[:, 0]
value2 = data2[:, 1]

data3 = np.loadtxt('./data/problemB_6.txt')
point3 = data3[:, 0]
value3 = data3[:, 1]

data4 = np.loadtxt('./data/problemB_8.txt')
point4 = data4[:, 0]
value4 = data4[:, 1]

# plot the data into curves
plt.plot(point1, value1, label="n=2")
plt.plot(point2, value2, label="n=4")
plt.plot(point3, value3, label="n=6")
plt.plot(point4, value4, label="n=8")

# plot the standard curve
x = np.arange(-5, 5, 10/1000)
plt.plot(x, [1/(1+i*i) for i in x], label="standard")

plt.title("Runge Phenomenon")
plt.legend()
plt.savefig("./pic/problemB.png")
plt.show()
